﻿using MediatR;
using Production_Set.API.Application.Commands.Resourctes;
using Return.Enum;
using SlaughterItem.Common.Infrastructures.Interfaces;
using THE_WIND_RISES.Common.Domans.Produce.DemandPlanning;
using THE_WIND_RISES.Common.Domans.Produce.Resources;
using THE_WIND_RISES.Common.Dtos;

namespace Production_Set.API.MaterialManagement.Delete
{
    public class MaterialPlanningDeleteHandler : IRequestHandler<MaterialPlanningDeleteCommon, Result>
    {
        private readonly IBaseRepository<MaterialPlanning> MaterialPlanningRepository;
        public MaterialPlanningDeleteHandler(IBaseRepository<MaterialPlanning> materialPlanningRepository)
        {
            MaterialPlanningRepository = materialPlanningRepository;
        }

        public async Task<Result> Handle(MaterialPlanningDeleteCommon request, CancellationToken cancellationToken)
        {
            var results = new Result() { Code = (int)CommonErrorCodes.Delete };

            string sql = "UPDATE MaterialPlanning SET IsDelete=1 WHERE MaterialPlanningId=" + request.MaterialPlanningId;
            var list = MaterialPlanningRepository.Update(sql, results);
            if (list != null)
            {
                results.Code = (int)CommonErrorCodes.Success;
                results.Msg = "删除成功";
            }

            return results;
        }
    }
}
